const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
const data = require('../data');
const postSQL = require('../../db/postSQL')

router.post('/getidpost', bodyParser.json(), (req, res) => {
    if (!req.body["userID"]
        || typeof req.body["userID"] != "number") {
        res.json({
            err: 1,
            message: '用户ID为空'
        })
    } else {

        // 下方改数据库操作代码，sql接口为postSQL.getidpost
        function getIDPost (posts, userName) {
            console.log({
                err: 200,
                userID: 1,
                userName: userName,
                postList: posts
            })
            res.json({
                err: 200,
                userID: 1,
                userName: userName,
                postList: posts
            })
        }
        //直接返回查询结果
        //要做userName的话就要在查询的时候用userId一并查询到userName，
        // 之后callback函数传入两个参数
        postSQL.getidpost(req.body["userID"], getIDPost);

    }
})

module.exports = router;